<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
	<jsp:include  page="/pages/common/head.jsp"/>
<body>
	<jsp:include  page="/pages/common/nav.jsp"/>

  <!-- Works Section
  ================================================== -->
  <div id="tf-works">
      <div class="container">
          <div class="section-header">
              <h2>每天更新 <span class="highlight">100 件<strong></strong></span></h2>
              <h5><em>一切都是天意</em></h5>
              <div class="fancy"><span><img src="img/favicon.ico" alt="..."></span></div>
          </div>
		  <div>
				<input type="date" id="selectDate">   
				<div><button type="button" class="btn btn-default btn-sm" onclick="save()">确定</button></div>
		  </div>
		  <div>
				<input type="date" id="selectPublishDate">   
				<div><button type="button" class="btn btn-default btn-sm" onclick="clearPublish()">清空publish</button></div>
		  </div>
          <div class="text-center">
              <ul class="list-inline cat ul-lineheight"> <!-- Portfolio Filter Categories -->
              <li><a href="#" onclick="loadCate('女装')">女装</a></li>
              <li><a href="#" onclick="loadCate('鞋包配饰')">鞋包配饰</a></li>
              <li><a href="#" onclick="loadCate('美妆个护')">美妆个护</a></li>
              <li><a href="#" onclick="loadCate('母婴')">母婴</a></li>
              </ul><!-- End Portfolio Filter Categories -->
      	   </div>
      </div><!-- End Container -->

      <div class="container"> <!-- container -->
			<div id="itemsWork" class="row text-center"></div>
      </div> <!-- End Container -->

  </div>
  <jsp:include  page="/pages/common/footer.jsp"/>
  <jsp:include  page="/pages/common/js.jsp"/>
</body>

<script>
var host = "${pageContext.request.contextPath}";

initDate();

function loadCate(cate) {
	$.post(host+"/catePage",{
		date:$("#selectDate").val(),
		cate:cate
	},function(data) {
		$("#itemsWork").html(data);
		$("#itemsWork").css("height","auto");
	});
}

function initDate() {
    //初始化时间控件
    var now = new Date() ;
        
    var nowYear = now.getFullYear() ; //年
    var nowMonth = now.getMonth()+1<10?"0"+(now.getMonth()+1):now.getMonth() ; //月
    var nowDay = now.getDate()<10?"0"+now.getDate():now.getDate() ; //日期
        
    var nowDate = nowYear+"-"+nowMonth+"-"+nowDay ;
        
    $("#selectDate").on("change",function(){
    	$.post(host+"/countNum",{date:$("#selectDate").val()},function(data){
    		$("#selectedNum").html(data.count);
    	});   
    });
    
    $("#selectDate").val(nowDate) ;
    $("#selectDate").trigger("change");
    
}


function changeItem(id,cate,obj) {
	$.post(host+"/changeItem",{id:id, cate:cate, date:$("#selectDate").val()},function(data){
		$(obj).closest(".box").parent().replaceWith(data);
	});
}

 function save() {
	$.post(host+"/save",{
		date:$("#selectDate").val(),
	},function(data) {
		alert(data);
	});
} 
 function clearPublish() {
		$.post(host+"/clearPublish",{
			date:$("#selectPublishDate").val(),
		},function(data) {
			alert(data);
		});
	} 
</script>
</html>
